<?php 
class class_DanhMucSanPham extends database
{
	function GetAllByLevel($level)
	{
		$this->setQuery('set names utf8');
		$this->Query();
	
		$sql = 'select * from danh_muc_san_pham where trangthai=1 and cap='.$level;
		
		$this->setQuery($sql);
		$table = $this->LoadAllRow();
		return $table;		
	}
	
	function GetAllByLevel1()
	{
		$this->setQuery('set names utf8');
		$this->Query();
	
		$sql = 'select * from danh_muc_san_pham';
		
		$this->setQuery($sql);
		$table = $this->LoadAllRow();
		return $table;		
	}
	function GetMaDanhMucByName($TenDanhMuc)
	{
		$this->setQuery('set names utf8');
		$this->Query();
	
		$sql = 'select * from danh_muc_san_pham where TenDanhMuc=\''.$TenDanhMuc.'\'';
		
		$this->setQuery($sql);
		$table = $this->loadOneRow();
		return $table;		
	}
	function GetMaDonViTinhByName($TenDonViTinh)
	{
		$this->setQuery('set names utf8');
		$this->Query();
	
		$sql = 'select * from don_vi_tinh where TenDonVitinh=\''.$TenDonViTinh.'\'';
		
		$this->setQuery($sql);
		$table = $this->loadOneRow();
		return $table;		
	}
	function GetNumRows()
	{
		$sql = 'select * from danh_muc_san_pham where trangthai=1' ;
		$this->setQuery($sql);
		$tb = $this->LoadAllRow();
		$num = count($tb);
		return $num;
	}
	
	function selectallpaging($start,$limit)
	{
		$this->setQuery('set names utf8');
		$this->Query();
	
		$sql = 'select * from danh_muc_san_pham where MaDanhMuc <> 1 and trangthai=1 limit '.$start.','.$limit ;
		
				
		$this->setQuery($sql);
		$table = $this->LoadAllRow();
		return $table;
	}
	function selectall()
	{
		$this->setQuery('set names utf8');
		$this->Query();
	
		$sql = 'select * from danh_muc_san_pham where MaDanhMuc <> 1 and trangthai=1 ';
		
				
		$this->setQuery($sql);
		$table = $this->LoadAllRow();
		return $table;
	}
	
	function chitiet($ma)
	{
		$this->setQuery('set names utf8');
		$this->Query();
		
		$sql = 'select * from danh_muc_san_pham where trangthai=1 and MaDanhMuc='.$ma;
		
		$this->setQuery($sql);
		$ret = $this->LoadAllRow();
		return $ret;
	}
	
	function add($TenDanhMuc)
	{
		$this->setQuery('set names utf8');
		$this->Query();
		
		$sql = 'insert into danh_muc_san_pham(TenDanhMuc) values(\''.$TenDanhMuc.'\')';
		
		$this->setQuery($sql);
		$kq = $this->Query();
		return $kq;
	}
	
	function updateall($MaDanhMuc,$TenDanhMuc)
	{
		$this->setQuery('set names utf8');
		$this->Query();
		
		$sql = 'update danh_muc_san_pham set TenDanhMuc=\''.$TenDanhMuc.'\' where MaDanhMuc='.$MaDanhMuc;
		
		$this->setQuery($sql);
		$kq = $this->Query();
		return $kq;
	}	
	
	
	function delete($ma)
	{
		$sql = 'update danh_muc_san_pham set trangthai=0 where MaDanhMuc='.$ma;
		
		
		$this->setQuery($sql);
		$rs = $this->Query();
		return $rs;
	}
	
}
?>